home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / lib / pmake / library.mk < prev    next >
Encoding:
Text File  |  1992-11-28  |  11.3 KB  |  435 lines

  1. #
  2. # Included makefile for creating a single library.  This Makefile assumes
  3. # that the library is contained in a single directory and its .md
  4. # subdirectories.
  5. #
  6. # $Header: /sprite/lib/pmake/RCS/library.mk,v 1.76 92/11/27 17:17:05 jhh Exp $ SPRITE (Berkeley)
  7. #
  8. # The makefile that includes this one should already have defined the
  9. # following variables:
  10. #    NAME        base name of library (e.g. tcl, sx, c, etc.)
  11. #    SRCS        all sources for the library for the current target
  12. #            machine
  13. #    ALLSRCS        all sources for the library, including all sources
  14. #            for all target machines
  15. #    HDRS        all header files (public and private)
  16. #    OBJS        object files from which to create it
  17. #    CLEANOBJS    object files to be removed as part of "make clean"
  18. #            (need not just be object files)
  19. #    PUBHDRS        publicly-available headers for the library (this
  20. #            contains only machine-independent headers)
  21. #    MDPUBHDRS    machine-dependent public headers for the library
  22. #            (for the current TM)
  23. #    LINTSRCS    additional sources to be used only when generating
  24. #            lint library
  25. #    TM        target machine type for object files etc.
  26. #    MACHINES    list of all target machines currently available
  27. #            for this program
  28. #    TYPE        a keyword identifying which sort of library this
  29. #            is;  used to determine where to install, etc.
  30. #
  31. # Optional variables that may be defined by the invoker:
  32. #    XAFLAGS        additional flags to pass to assembler
  33. #    XCFLAGS        additional flags to pass to compiler
  34. #    DEPFLAGS    additional flags to pass to makedepend
  35. #    no_targets    if defined, this file will not define all of the
  36. #            basic targets (make, make clean, etc.)
  37. #
  38.  
  39. #
  40. # The variables below should be defined in md.mk, but they are given
  41. # default values just in case md.mk doesn't exist yet.
  42. #
  43. CLEANOBJS    ?=
  44. HDRS        ?=
  45. MDPUBHDRS    ?=
  46. OBJS        ?=
  47. SRCS        ?=
  48.  
  49. CSRCS        ?= $(SRCS:M*.c)
  50. SSRCS        ?= $(SRCS:M*.s)
  51. CCSRCS        ?= $(SRCS:M*.cc)
  52.  
  53. #
  54. # Define search paths for include files and source files (for sources,
  55. # must be sure to look both in this directory and in the machine-dependent
  56. # one).
  57. #
  58. .PATH.a        : # Clear out
  59. .PATH.h        : # Clear out previous
  60. .PATH.h        : $(TM).md /sprite/lib/include /sprite/lib/include/$(TM).md
  61. .PATH.c        : # Clear out previous
  62. .PATH.c        : $(TM).md
  63. .PATH.s        : # Clear out previous
  64. .PATH.s        : $(TM).md
  65.  
  66. #
  67. # System programs -- assign conditionally so they may be redefined in
  68. # including makefile
  69. #
  70. BINDIR        ?= /sprite/cmds.$(MACHINE)
  71.  
  72. AS        ?= $(BINDIR)/as
  73. CC        ?= $(BINDIR)/cc
  74. CHGRP        ?= $(BINDIR)/chgrp
  75. CHMOD        ?= $(BINDIR)/chmod
  76. CHOWN        ?= $(BINDIR)/chown
  77. CP        ?= $(BINDIR)/cp
  78. CPLUSPLUS    ?= $(BINDIR)/g++
  79. CPP        ?= $(BINDIR)/cpp -traditional -$
  80. CTAGS        ?= $(BINDIR)/ctags
  81. ECHO        ?= $(BINDIR)/echo
  82. LINT        ?= $(BINDIR)/lint
  83. MAKEDEPEND    ?= $(BINDIR)/makedepend
  84. MV        ?= $(BINDIR)/mv
  85. RANLIB        ?= $(BINDIR)/ranlib
  86. RM        ?= $(BINDIR)/rm
  87. SED        ?= $(BINDIR)/sed
  88. TEST            ?= $(BINDIR)/test
  89. TOUCH        ?= $(BINDIR)/touch
  90. UPDATE        ?= $(BINDIR)/update
  91.  
  92. # The Ultrix ar doesn't handle truncated file names correctly.
  93.  
  94. #if !empty(MACHINE:Mds3100) || !empty(MACHINE:Mds5000)
  95. AR = $(BINDIR)/ar.sprite
  96. #else
  97. AR = $(BINDIR)/ar
  98. #endif
  99.  
  100. #
  101. # Several variables (such as where to install) are set based on the
  102. # TYPE variable.  Of course, any of these variables can be overridden
  103. # by explicit assignments.
  104. #
  105. TYPE        ?= unknown
  106. #if !empty(TYPE:Msprite)
  107. INCLUDEDIR    ?= /sprite/lib/include
  108. INSTALLDIR    ?= /sprite/lib
  109. INSTALLMAN    ?= /sprite/man/lib/$(NAME)
  110. LINTDIR        ?= /sprite/lib/lint
  111. #elif !empty(TYPE:Mx)
  112. INCLUDEDIR    ?= /X/lib/include
  113. INSTALLDIR    ?= /X/lib
  114. INSTALLMAN    ?= /X/man/lib/$(NAME)
  115. LINTDIR        ?= /X/lib/lint
  116. #elif !empty(TYPE:MX11R4)
  117. INCLUDEDIR    ?= /X11/R4/lib/include/X11
  118. INSTALLDIR    ?= /X11/R4/lib
  119. INSTALLMAN    ?= /X11/R4/man/lib/$(NAME)
  120. LINTDIR        ?= /X11/R4/lib/lint
  121. #elif !empty(TYPE:Mpersonal)
  122. INCLUDEDIR    ?= $(HOME)/lib/include
  123. INSTALLDIR    ?= $(HOME)/lib
  124. INSTALLMAN    ?= $(HOME)/man/lib/$(NAME)
  125. LINTDIR        ?= $(HOME)/lib/lint
  126. #ifndef        USERBACKUP
  127. NOBACKUP    =
  128. #endif
  129. #elif !empty(TYPE:Mlocal)
  130. INCLUDEDIR    ?= /local/lib/include
  131. INSTALLDIR    ?= /local/lib
  132. INSTALLMAN    ?= /local/man/lib/$(NAME)
  133. LINTDIR        ?= /local/lib/lint
  134. #else
  135. INCLUDEDIR    ?=
  136. INSTALLDIR    ?=
  137. INSTALLMAN    ?=
  138. LINTDIR        ?=
  139. #endif
  140.  
  141. #
  142. # Figure out what stuff we'll pass to sub-makes.
  143. #
  144. PASSVARS    = 'INSTALLDIR=$(INSTALLDIR)' $(.MAKEFLAGS)
  145. #ifdef        XCFLAGS
  146. PASSVARS    += 'XCFLAGS=$(XCFLAGS)'
  147. #endif
  148. #ifdef        XAFLAGS
  149. PASSVARS    += 'XAFLAGS=$(XAFLAGS)'
  150. #endif
  151. #ifdef        NOBACKUP
  152. PASSVARS    += 'NOBACKUP=$(NOBACKUP)'
  153. #endif
  154. #ifdef        BACKUPAGE
  155. PASSVARS    += 'BACKUPAGE=$(BACKUPAGE)'
  156. #endif
  157.  
  158. #
  159. # Flags everyone should have. XCFLAGS, XAFLAGS and CLINTFLAGS are provided
  160. # for the user to add flags for CC, AS or LINT from the command line.
  161. #
  162.  
  163. #include    <tm.mk>
  164. CTFLAGS        ?= -wt
  165. DEPFLAGS    ?=
  166. INSTALLFLAGS    ?=
  167. INSTALLMANFLAGS    ?=
  168. LINTFLAGS    ?= -m$(TM)
  169. LINTFLAGS    += -u 
  170. XAFLAGS        ?=
  171. XCFLAGS        ?=
  172. #
  173. # The .INCLUDES variable already includes directories that should be
  174. # used by cc and other programs by default.  Remove them, just so that
  175. # the output looks cleaner.
  176. #
  177.  
  178. #include <debugflags.mk>
  179.  
  180. CFLAGS        += $(OFLAG) $(TMCFLAGS) $(XCFLAGS) -I.
  181.  
  182. #
  183. # Since the dec compiler doesn't include /sprite/lib/include, we must leave
  184. # the path as is when TM=ds3100.
  185. #
  186.  
  187. CFLAGS        += $(.INCLUDES:S|^-I/sprite/lib/include$||g:S|^-I/sprite/lib/include/$(TM).md$||g)
  188. #if empty(TM:Mds3100)
  189. AFLAGS        += $(TMAFLAGS) $(XAFLAGS)
  190. #else
  191. CFLAGS        += -I/sprite/lib/include -I/sprite/lib/include/$(TM).md
  192. AFLAGS        += $(.INCLUDES)
  193. #endif
  194.  
  195. .MAKEFLAGS    : -C
  196.  
  197. #
  198. # Transformation rules: these have special features to place .o files
  199. # in md subdirectories, run preprocessor over .s files, and generate
  200. # .po files for profiling.
  201. #
  202.  
  203. .SUFFIXES    : .po .go
  204.  
  205. .c.o        :
  206.     $(RM) -f $(.TARGET)
  207.     $(CC) $(CFLAGS) -c $(.IMPSRC) -o $(.TARGET)
  208. .c.go        :
  209.     $(RM) -f $(.TARGET)
  210.     $(CC) $(CFLAGS) $(GFLAG) -c $(.IMPSRC) -o $(.TARGET)
  211. .c.po        :
  212.     $(RM) -f $(.TARGET)
  213. #ifdef NOPROFILE        
  214.     $(CC) $(CFLAGS) -DPROFILE -c $(.IMPSRC) -o $(.TARGET)
  215. #else        
  216.     $(CC) $(CFLAGS) -p -DPROFILE -c $(.IMPSRC) -o $(.TARGET)
  217. #endif        
  218.  
  219. .s.go .s.po .s.o:
  220. #if empty(TM:Mds3100) && empty(TM:Mjhh) && empty(TM:Mcleands3100)
  221.     $(CPP) $(CFLAGS:M-[IDU]*) -m$(TM) -D$(TM) -D_ASM $(.IMPSRC) > $(.PREFIX).pp
  222.     $(AS) -o $(.TARGET) $(AFLAGS) $(.PREFIX).pp
  223.     $(RM) -f $(.PREFIX).pp
  224. #else
  225.     $(RM) -f $(.TARGET)
  226.     $(AS) $(AFLAGS) $(.IMPSRC) -o $(.TARGET)
  227. #endif
  228.  
  229. .cc.o    :
  230.     $(RM) -f $(.TARGET)
  231.     $(CPLUSPLUS) $(CFLAGS) -c $(.IMPSRC) -o $(.TARGET)
  232. .cc.go    :
  233.     $(RM) -f $(.TARGET)
  234.     $(CC) $(CFLAGS) $(GFLAG) -c $(.IMPSRC) -o $(.TARGET)
  235. .cc.po        :
  236.     $(RM) -f $(.TARGET)
  237. #ifdef NOPROFILE        
  238.     $(CPLUSPLUS) $(CFLAGS) -DPROFILE -c $(.IMPSRC) -o $(.TARGET)
  239. #else        
  240.     $(CPLUSPLUS) $(CFLAGS) -p -DPROFILE -c $(.IMPSRC) -o $(.TARGET)
  241. #endif        
  242.  
  243.  
  244. #
  245. # The rule below is needed to make archives, so that the archive
  246. # member depends on the corresponding .o (or .po) file.  For some
  247. # reason, this rule doesn't work without some commands (and the ...
  248. # is enough).
  249. .go.a .po.a .o.a    :
  250.     ...
  251.  
  252. #
  253. # MAKEINSTALLHDRS usage:
  254. #    <target> : MAKEINSTALLHDRS
  255. # All of the public headers files get updated to INCLUDEDIR.
  256. #
  257. MAKEINSTALLHDRS    : .USE .SILENT
  258. #if !empty(PUBHDRS)
  259.     $(UPDATE) -l -m 664 -t $(INSTALLFLAGS) $(PUBHDRS) $(INCLUDEDIR)
  260. #endif
  261. #if !empty(MDPUBHDRS)
  262.     $(UPDATE) -l -m 664 -t $(INSTALLFLAGS) \
  263.         $(MDPUBHDRS) $(INCLUDEDIR)/$(TM).md
  264. #endif
  265.  
  266. #
  267. # MAKEINSTALLLIB usage:
  268. #    <target> : <source> MAKEINSTALLLIB
  269. # Will copy over a library and re-ranlib it.
  270. #
  271. MAKEINSTALLLIB : .USE
  272.     $(RM) -f $(.TARGET)
  273.     $(CP) $(.ALLSRC) $(.TARGET)
  274.     $(RANLIB) $(.TARGET)
  275.  
  276. #
  277. # MAKELINT usage:
  278. #    <fluff-file> : <sources to be linted> MAKELINT
  279. #
  280. # <fluff-file> is the place to store the output from the lint.
  281. #
  282. MAKELINT    : .USE
  283.     $(RM) -f $(.TARGET)
  284.     $(LINT) $(LINTFLAGS) $(CFLAGS:M-[IDU]*) $(.ALLSRC) \
  285.         > $(.TARGET) 2>&1
  286.  
  287. #
  288. # MAKEDEPEND usage:
  289. #    <dependency-file> : <sources> MAKEDEPEND
  290. #
  291. # Generate dependency file suitable for inclusion in future makes.
  292. #
  293. MAKEDEPEND    : .USE
  294.     @$(TOUCH) $(.TARGET)
  295. #if empty(TM:Mds3100)
  296.     $(MAKEDEPEND) $(CFLAGS:M-[ID]*) -m $(TM) -w80 -f $(.TARGET) $(.ALLSRC)
  297. #else
  298.     $(MAKEDEPEND) $(CFLAGS:M-[ID]*:S|^-I/sprite/lib/include$||g:S|^-I/sprite/lib/include/$(TM).md$||g) -m $(TM) -w80 -f $(.TARGET) $(.ALLSRC)
  299. #endif
  300.     @$(MV) -f $(.TARGET) $(.TARGET).tmp
  301.     @$(SED) -e '/^#/!s|^\([^:]*\)\.o[     ]*:|$(TM).md/\1.po $(TM).md/\1.go $(TM).md/&|' <$(.TARGET).tmp > $(.TARGET)
  302.     @$(RM) -f $(.TARGET).tmp
  303.  
  304. #ifndef no_targets
  305. #
  306. # We should define the main targets.  See the Mkmf man page for details.
  307. #
  308.  
  309. REGLIB            = $(TM).md/lib$(NAME).a
  310. PROFLIB            = $(TM).md/lib$(NAME)_p.a
  311. DEBUGLIB        = $(TM).md/lib$(NAME)_g.a
  312. LINTLIB            = $(TM).md/llib-l$(NAME).ln
  313. INSTLIB            = $(INSTALLDIR)/$(REGLIB)
  314. INSTPROFILE        = $(INSTALLDIR)/$(PROFLIB)
  315. INSTDEBUG        = $(INSTALLDIR)/$(DEBUGLIB)
  316.  
  317. default            : $(REGLIB)
  318. $(REGLIB)        : $(REGLIB)($(OBJS))
  319.     $(AR) $(ARFLAGS) $(.TARGET) $(.OODATE)
  320.     $(RANLIB) $(.TARGET)
  321. #if !empty(CLEANOBJS:M*.o)
  322.     rm -rf $(CLEANOBJS:M*.o)
  323. #endif
  324.  
  325. clean tidy        ::
  326.     $(RM) -f $(REGLIB) $(DEBUGLIB) $(PROFLIB) $(CLEANOBJS) \
  327.         $(CLEANOBJS:M*.o:S/.o$/.po/g) $(CLEANOBJS:M*.o:S/.o$/.go/g) \
  328.         $(LINTLIB) y.tab.c lex.yy.c core a.out *~ $(TM).md/*~ \
  329.         version.h $(TM).md/lint
  330.  
  331. debug            : $(DEBUGLIB)
  332. $(DEBUGLIB)        : $(DEBUGLIB)($(OBJS:S/.o$/.go/g))
  333.     $(AR) $(ARFLAGS) $(.TARGET) $(.OODATE)
  334.     ...
  335.     $(RANLIB) $(.TARGET)
  336. #if !empty(CLEANOBJS:M*.o)
  337.     rm -rf $(CLEANOBJS:M*.o:S/.o$/.go/g)
  338. #endif
  339.  
  340. DEPFILE = $(TM).md/dependencies.mk
  341. depend            : $(DEPFILE)
  342. $(DEPFILE)        ! $(CSRCS) $(CCSRCS) $(SSRCS) MAKEDEPEND
  343.  
  344. #if empty(TYPE:Munknown)
  345. #ifndef NOLINT
  346. install            :: installlib installhdrs installlint installman
  347. #else
  348. install            :: installlib installhdrs installman
  349. #endif
  350. installdebug        :: $(DEBUGLIB) debuglink
  351. debuglink        !
  352.     rm -f $(INSTDEBUG)
  353.     ln -s `pwd`/$(DEBUGLIB) $(INSTDEBUG)
  354. installhdrs        :: MAKEINSTALLHDRS
  355. installlib        :: $(INSTALLDIR)/$(REGLIB)
  356. installlint        :: $(LINTDIR).$(TM)/llib-l$(NAME).ln
  357. #if empty(MANPAGES)
  358. installman        :: .SILENT
  359.     echo "No man pages for library $(NAME)?  Please write some."
  360. #elif !empty(MANPAGES:MNONE)
  361. installman        ::
  362. #else
  363. installman        :: .SILENT
  364.     $(UPDATE) -m 444 -l $(INSTALLMANFLAGS) $(MANPAGES) $(INSTALLMAN)
  365. #endif
  366. installprofile        :: $(INSTPROFILE)
  367. $(INSTLIB)        : $(REGLIB) MAKEINSTALLLIB
  368. $(INSTPROFILE)        : $(PROFLIB) MAKEINSTALLLIB
  369. #else
  370. #
  371. # The targets below are used if there's no known place to install this
  372. # library:  just output a warning message.
  373. #
  374. install installdebug installlint installlib installman installprofile \
  375. installquick        :: .SILENT
  376.     echo "Can't install library $(NAME): no install directory defined"
  377. #endif
  378.  
  379. library            : $(REGLIB)
  380.  
  381. lint            : $(TM).md/lint
  382. $(TM).md/lint        : $(SRCS:M*.c) MAKELINT
  383.  
  384. $(LINTDIR).$(TM)/llib-l$(NAME).ln    : $(LINTLIB) .SILENT
  385.     $(UPDATE) -m 664 $(INSTALLFLAGS) $(LINTLIB) $(.TARGET)
  386. lintlib            : $(LINTLIB)
  387. $(LINTLIB)        : $(CSRCS) $(HDRS) $(LINTSRCS)
  388.     $(RM) -f $(.TARGET)
  389.     $(LINT) -C$(NAME) $(CFLAGS:M-[IDU]*) -DLINTLIB $(LINTFLAGS) \
  390.         $(.ALLSRC:M*.c) $(.ALLSRC:M*.lint)
  391.     $(MV) llib-l$(NAME).ln $(.TARGET)
  392.  
  393. mkmf            ::
  394.     mkmf
  395.  
  396. newtm            :: .SILENT
  397.     if $(TEST) -d $(TM).md; then
  398.         true
  399.     else
  400.         mkdir $(TM).md;
  401.         chmod 775 $(TM).md;
  402.         mkmf -m$(TM)
  403.     fi
  404.  
  405. profile            : $(PROFLIB)
  406. $(PROFLIB)        : $(PROFLIB)($(OBJS:S/.o$/.po/g))
  407.     $(AR) $(ARFLAGS) $(.TARGET) $(.OODATE)
  408.     ...
  409.     $(RANLIB) $(.TARGET)
  410. #if !empty(CLEANOBJS:M*.o)
  411.     rm -rf $(CLEANOBJS:M*.o:S/.o$/.po/g)
  412. #endif
  413.  
  414. tags            :: $(ALLSRCS:M*.c) $(HDRS)
  415.     $(CTAGS) $(CTFLAGS) $(ALLSRCS:M*.c)
  416.  
  417. DISTFILES    ?=
  418.  
  419. dist        !
  420. #if defined(DISTDIR) && !empty(DISTDIR)
  421.     for i in Makefile local.mk $(TM).md/md.mk \
  422.         $(MANPAGES) $(SRCS) $(HDRS) $(DISTFILES)
  423.     do
  424.     if $(TEST) -e $${i}; then
  425.         $(UPDATE)  $${i} $(DISTDIR)/$${i} ;else true; fi
  426.     done
  427. #else
  428.     @echo "Sorry, no distribution directory defined"
  429. #endif
  430.  
  431. #include        <all.mk>
  432. #endif no_targets
  433.  
  434. #include        <rdist.mk>
  435.